-- probability_absorb
-- created by zhuangsl
-- 攻击时概率吸血

return {
    apply = function(prop, baseValue)
        return prop[3];
    end,

    -- 对敌伤害触发
    trigger = function(who, prop, damage)
        -- 概率触发
        if DungeonM.getRandSeed("probability_absorb") % 1000 >= prop[3] then
            return;
        end

        local rate = tonumber(prop[2]);
        local hp = math.modf(damage * rate / 1000);
        if hp <= 0 then
            hp = 1;
        end

        if who.type == OBJECT_TYPE_USER then
            BonusM.doBonus({ 2, "hp", hp, }, "prop probability_absorb");
            EventMgr.fire(event.HP_VAMPIRE, hp);
        else
            who:addAttrib("hp", hp);
        end

        -- 触发特技发动事件
        EventMgr.fire(event.SPECIAL_SKILL_TRIGGER, { propId = prop[1] });

        return hp;
    end,

    record = function(target, prop, path)
        return false;
    end
};
